﻿

 var mnuItemClick = function (itm) {
                    var arr = itm.ownerCt.args.split('_');
                    currentMap[this.id] = parseInt(arr[2]);
                    panelMapping.refreshMap();
                };

var ReadTable2Down = function (itm) {
    var arr = itm.ownerCt.args.split('_');

    var table = Ext.get(arr[0]).dom;

    var startRow = arr[1];

    var lastFullRow = table.rows[startRow];

    var rowFullSizeLength = lastFullRow.cells.length;

    var cell = null;

    for (var i = startRow; i < table.rows.length; i++) {
       
        if (table.rows[i].cells.length == rowFullSizeLength)
                                            lastFullRow = table.rows[i];

            PopulateRowSpanCells(lastFullRow,table.rows[i]);
    }
};

function  PopulateRowSpanCells(lastFullRow, rowSpanRow) {
    var tdRowspanNumbers=[];
    var result = [];
    var j = 0;
    for (var i = 0; i < lastFullRow.cells.length; i++) {
        if (lastFullRow.cells[i].rowSpan > 1) {
            tdRowspanNumbers.push(i);
            result.push(lastFullRow.cells[i].innerText);
        }
        else {
            result.push(rowSpanRow.cells[j].innerText);
            j = j + 1;
        }
    }
    return result; 
};

var ShowEditor = function (p) {
    wndWordTabEditor.setPosition(currentXY[0], currentXY[1]);
    wndWordTabEditor.show();
};

//var TdContextMenu = Ext.extend(Ext.menu.Menu, {
var contextMenuTD = new Ext.menu.Menu({
    items: [{
        id: 'clMNN',
        text: 'МНН',
        iconCls: 'edit',
        handler: mnuItemClick,
        arg: ''
    },
     {
         id: 'clTradeNM',
         text: 'Торговое наименование',
         iconCls: 'edit',
         handler: mnuItemClick,
         arg: ''
     },
        {
            id: 'clInfo',
            text: 'Характеристики',
            iconCls: 'edit',
            handler: mnuItemClick,
            arg: ''
        },
        {
            id: 'clCount',
            text: 'Количество',
            iconCls: 'edit',
            handler: mnuItemClick,
            arg: ''
        },
        {
            id: 'clPriceItem',
            text: 'Цена за единицу',
            iconCls: 'edit',
            handler: mnuItemClick
        },
        {
            id: 'clPrice',
            text: 'Цена всего',
            iconCls: 'edit',
            handler: mnuItemClick
        },
      
        {
            text: 'Редактор',
            iconCls: 'edit',
            handler: ShowEditor
        },
         {
             text: 'Считать табличку',
             iconCls: 'edit',
             handler: ReadTable2Down
         }
     ]
});

